package com.aaa.service.sas.impl;

import cn.hutool.core.util.ObjectUtil;
import com.aaa.aspect.InsertAnn;
import com.aaa.aspect.UpdateAnn;
import com.aaa.dao.sas.QuestionSasDao;
import com.aaa.entity.PageSortEntity;
import com.aaa.entity.sas.QuestionSas;
import com.aaa.service.sas.QuestionSasService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author ：马明钢
 * @date ：Created in 2022/8/29 15:02
 * @description：
 * @modified By：
 * @version:
 */
@Service
public class QuestionSasServiceImpl implements QuestionSasService {
    @Autowired
    QuestionSasDao questionSasDao;

    /**
     *  * @create by: 马明钢 
     *
     * @param page 
     * @return com.github.pagehelper.Page 
     * @description: 分页排序查询 
     * @create time: 2022/9/2 19:32 * @param ts
     */
    @Override
    public Page queryAll(PageSortEntity page, QuestionSas questionSas) {
        PageHelper.startPage(page.getPage(), page.getLimit(), page.getOrderString());
        List<QuestionSas> list = questionSasDao.queryAll(questionSas);
        Page page1 = (Page) list;
        return page1;
    }

    /**
     *  * @create by: 马明钢 
     *
     * @return boolean 
     * @description:  保存
     * @create time: 2022/9/2 19:33 * @param ts 
     */
    @InsertAnn
    @Override
    public boolean insert(QuestionSas questionSas) {
        return questionSasDao.insert(questionSas);
    }

    /**
     *  * @create by: 马明钢 
     *
     * @return boolean 
     * @description:  根据id删除
     * @create time: 2022/9/2 19:34 * @param id 
     */
    @Override
    public boolean delete(String id) {
        return questionSasDao.delete(id);
    }

    /**
     *  * @create by: 马明钢 
     *
     * @return boolean 
     * @description:  修改
     * @create time: 2022/9/2 19:34 * @param ts 
     */
    @UpdateAnn
    @Override
    public boolean update(QuestionSas questionSas) {
        return questionSasDao.update(questionSas);
    }

    /**
     *  * @create by: 马明钢 
     *
     * @return boolean 
     * @description:  添加和修改题目是否重复
     * @create time: 2022/9/2 19:36 * @param ts 
     */
    @Override
    public boolean repetitionName(QuestionSas ts) {
        QuestionSas tss = questionSasDao.repetitionName(ts);
        if (ObjectUtil.isEmpty(tss) || ts.getId().equals(tss.getId())) {
            return true;
        } else {
            return false;
        }
    }

    @Override
    public boolean repetitionID(QuestionSas ts) {
        QuestionSas questionSas = questionSasDao.repetitionID(ts);
        if (ObjectUtil.isNotEmpty(questionSas)) {
            return false;
        }
        return true;
    }
}